package com.hch.algorithm.breadth;

import java.util.*;

/**
 * @author HeCongHui
 * @date 2022/7/8 09:51
 */
public class BreadthSearch {
    /**
     * 自己的名字
     */
    private String yourself;
    /**
     * 用于存储相邻关系
     */
    private Map<String, List<String>> graphRel;
    /**
     * ¬先进献出，方便查找关系最近的人
     */

    private Queue<String> personQueue;
    /**
     * 用于存储检查过的人
     */
    private List<String> searched;

    public BreadthSearch(String yourself, Map<String, List<String>> graphRel) {
        this.yourself = yourself;
        this.graphRel = graphRel;
        this.personQueue = new LinkedList<>();
        this.searched = new ArrayList<>();
    }

    public List<String> searchBestRel() {

        List<String> bestList = new ArrayList<>();
        //将自己的关系链上的人拿到
        List<String> personRelList = this.graphRel.get(this.yourself);
        for (String person : personRelList) {
            this.personQueue.offer(person);
        }
        while (!this.personQueue.isEmpty()) {
            String rel = this.personQueue.poll();
            if (!this.searched.contains(rel)) {
                if (searchIsRelative(rel)) {
                    System.out.println(rel + " is best rel");
                    bestList.add(rel);
                } else {
                }

                this.searched.add(rel);
            }

        }
        return null;
    }

    private Boolean searchIsRelative(String rel) {
        return false;
    }
}
